var vm = new Vue({
    el: '#app',
    data:{
        host,
        username: sessionStorage.username || localStorage.username,
        user_id: sessionStorage.user_id || localStorage.user_id,
        token: sessionStorage.token || localStorage.token,
        news_list:[],
        categories:[],
        cid:get_query_string("cid",0),
        dateFormat (time){}
    },
    mounted: function(){
        this.get_category();
        this.get_newslist();
      },
    methods: {
        // 获取新闻分类
        get_category: function () {
            axios.get(this.host + '/news_category/', {
                responseType: 'json'
            })
                .then(response => {
                    this.categories = response.data;
                })
                .catch(error => {
                    console.log(error.response.data)
                })
        },
        // 获取新闻列表
        get_newslist: function () {
            axios.get(this.host + '/news_list/' + this.cid + '/', {
                responseType: 'json'
            })
                .then(response => {
                    this.news_list = response.data;
                })
                .catch(error => {
                    console.log(error.response.data)
                })

        },
        dateSwitch:function (time) {
           return dateFormat(time);
        },
    },

    });
